package com.rs.game.npc.wguild;

import com.rs.game.Animation;
import com.rs.game.Entity;
import com.rs.game.World;
import com.rs.game.WorldTile;
import com.rs.game.item.Item;
import com.rs.game.npc.NPC;
import com.rs.game.npc.combat.NPCCombatDefinitions;
import com.rs.game.player.Player;
import com.rs.game.player.content.warriorsguild.WarriorSet;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;

@SuppressWarnings("serial")
public class WGuildNPC extends NPC {

	public WGuildNPC(int id, WorldTile tile) {
		super(id, tile, -1, true, true);
	}

	@Override
	public void sendDeath(Entity source) {
		final NPCCombatDefinitions defs = getCombatDefinitions();
		Player player = (Player) source;
		WarriorSet set = (WarriorSet) player.getTemporaryAttributes().get("warriors_guild_armour");
		if (set != null)
			for (Item item : set.getArmour()) {
				World.addGroundItem(item, getWorldTile(), player, false, 180, true);
			}
		resetWalkSteps();
		getCombat().removeTarget();
		setNextAnimation(null);
		player.getPlayerData().getGamePoints()[0] += (set.ordinal() + 1) * 10;
		player.getInterfaceManager().sendOverlay(1057, player.getDisplayMode() > 1);
		player.getPackets().sendConfig(2030, player.getPlayerData().getGamePoints()[0]);
		getTemporaryAttributes().remove("target_name");
		WorldTasksManager.schedule(new WorldTask() {
			int loop;
			@Override
			public void run() {
				if (loop == 0) {
					setNextAnimation(new Animation(defs.getDeathEmote()));
				} else if (loop >= defs.getDeathDelay()) {
					reset();
					setLocation(getRespawnTile());
					finish();
					if (!isSpawned())
						setRespawnTask();
					stop();
				}
				loop++;
			}
		}, 0, 1);
	}

}